package com.dsj.sx_admin.controller;


import com.dsj.sx_admin.model.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @描述  接口开发：接收参数的方式主要有：？、form、（基本类型或对象）；路径（pathvarable）、json（requestBOdy）
 *    调用接口：urlConnection（jdk）、httpclient（Apache）、resttemplate（Spring）、feign（SpringCloud）
 * @创建人 wangyue
 * @创建时间2019/9/911:22
 */
@RestController
@RequestMapping("user")
public class UserController {

    @RequestMapping("list")
    public List<User> list(String name){
        List<User> userlist = new ArrayList<User>();
        User user1 = new User("1","张三");
        User user2 = new User("2","李四");
        User user3 = new User("3",name);
        userlist.add(user1);
        userlist.add(user2);
        userlist.add(user3);
        return userlist;
    }
    @RequestMapping("list3/{name}")
    public List<User> list3(@PathVariable String name){
        List<User> userlist = new ArrayList<User>();
        User user1 = new User("1","张三");
        User user2 = new User("2","李四");
        User user3 = new User("3",name);
        userlist.add(user1);
        userlist.add(user2);
        userlist.add(user3);
        return userlist;
    }
    @RequestMapping("list1")
    public List<User> list1(User user){
        List<User> userlist = new ArrayList<User>();
        User user1 = new User("1","张三");
        User user2 = new User("2","李四");
        userlist.add(user1);
        userlist.add(user2);
        userlist.add(user);
        return userlist;
    }

    @RequestMapping("list2")
    public List<User> list2(@RequestBody User user){
        List<User> userlist = new ArrayList<User>();
        User user1 = new User("1","张三");
        User user2 = new User("2","李四");
        userlist.add(user1);
        userlist.add(user2);
        userlist.add(user);
        return userlist;
    }
    @RequestMapping("getOne")
    public User getOne(String id){
        if(id.equals("1")){
            return new User("1","张三");
        } else{
            return new User("2","李四");
        }
    }
}
